Imports DotNetPM.Business.Questionnaire

Partial Class Modules_Questionnaires_Management_QuestionnairePerm
    Inherits System.Web.UI.Page

    Private Const tblBody As String _
        = "border-color:#11518D;border-style:solid;border-width:2px;border-collapse:collapse;background-color:White;BORDER-TOP: #11518D 3px solid;"
    Private Const tbl1f As String _
        = "background-image:url(../../images/1f.gif);background-repeat:no-repeat;height:23px;width: 12px;"
    Private Const tbl2f As String _
        = "background-image:url(../../images/2f.gif);background-repeat:no-repeat;height:23px;width:35px;"
    Private Const tbl3f As String _
        = "background-image:url(../../images/3f.gif);background-repeat:no-repeat;height:23px;width:35px;"
    Private Const tbl1b As String _
        = "background-image:url(../../images/1b.gif);background-repeat:no-repeat;height:23px;width:12px;"
    Private Const tbl2b As String _
        = "background-image:url(../../images/2b.gif);background-repeat:no-repeat;height:23px;width:35px;"
    Private Const tbl3b As String _
        = "background-image:url(../../images/3b.gif);background-repeat:no-repeat;height:23px;width:35px;"
    Private Const tbl2 As String _
        = "background-image:url(../../images/2.gif);background-repeat:no-repeat;height:23px;"
    Private Const tblb As String _
        = "background-image:url(../../images/0b.gif);vertical-align:middle;text-align:center;"
    Private Const tblf As String _
        = "background-image:url(../../images/0f.gif);vertical-align:middle;text-align:center;"


    Private _questionnaire As Questionnaire

#Region "Page Events"

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        'Response.Write("Page_Init<br/>")
        If String.IsNullOrEmpty(Session("questionnaire_questionnaireId")) Then
            Response.Redirect("QuestionnaireManager.aspx")
        End If
    End Sub

    Protected Sub Page_LoadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadComplete
        'Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Response.Write("Page_Load<br/>")
        If lblb.Visible Then
            'Editing
            tbf1.Style.Value = tbl1b
            tbf2.Style.Value = tblb
            tbf3.Style.Value = tblb
            tbf4.Style.Value = tbl2b
            tbb2.Style.Value = tblf
            tbb3.Style.Value = tblf
            Tbb4.Style.Value = tbl3f
        Else
            tbf1.Style.Value = tbl1f
            tbf2.Style.Value = tblf
            tbf3.Style.Value = tblf
            tbf4.Style.Value = tbl2f
            tbb2.Style.Value = tblb
            tbb3.Style.Value = tblb
            Tbb4.Style.Value = tbl3b
        End If
        tbl.Style.Value = tblBody
        _questionnaire = QuestionnaireODS.Provider.GetQuestionnaire(Session("questionnaire_questionnaireId"))
        With _questionnaire
            lblStudyID.Text = .StudyID
            lblInstrument.Text = .InstrumentID
            lblDescription.Text = .Description
        End With
    End Sub

    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
        Dim orgValue As String
        If lblb.Visible Then
            orgValue = _questionnaire.EdtingPermission
        Else
            orgValue = _questionnaire.TakingPermission
        End If
        Page.ClientScript.RegisterStartupScript(Me.GetType, Me.ClientID, _
        "var orgValue='" & orgValue & "';var butSaveId='" & butSave.ClientID & "';", True)
    End Sub

#End Region

    Protected Sub butSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butSave.Click
        Dim perm As String = String.Empty
        Dim bFirst As Boolean = True
        For Each gvr As GridViewRow In gvRoles.Rows
            Dim cbAllowed As CheckBox = gvr.Cells(0).FindControl("cbAllowed")
            If cbAllowed.Enabled AndAlso cbAllowed.Checked Then
                If bFirst Then
                    perm = cbAllowed.Text
                    bFirst = False
                Else
                    perm &= "|" & cbAllowed.Text
                End If
            End If
        Next
        If lblf.Visible Then
            'Response.Write(perm & ":Taking<br/>")
            QuestionnaireODS.UpdateQuestionnaireTakingPerm( _
                Session("questionnaire_questionnaireId"), perm)
        Else
            'Response.Write(perm & ":Editing<br/>")
            QuestionnaireODS.UpdateQuestionnaireEditingPerm( _
                Session("questionnaire_questionnaireId"), perm)
        End If
    End Sub

    Protected Sub butCancel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butCancel.Click
        Response.Redirect("QuestionnaireManager.aspx")
    End Sub

    Protected Sub lbBack_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbBack.Click
        Response.Redirect("QuestionnaireManager.aspx")
    End Sub

    Protected Sub lbb_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbb.Click
        'Response.Write("lbb_Click<br/>")
        lbf.Visible = True
        lblf.Visible = False
        lbb.Visible = False
        lblb.Visible = True
    End Sub

    Protected Sub lbf_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lbf.Click
        'Response.Write("lbf_Click<br/>")
        lbf.Visible = False
        lblf.Visible = True
        lbb.Visible = True
        lblb.Visible = False
    End Sub

End Class
